angular.module('module.advertisement').controller('AdDetailController', AdDetailController);

AdDetailController.$inject = ['$state','$stateParams','$localStorage','AdvertisementService'];

function AdDetailController( $state, $stateParams, $localStorage, AdvertisementService) {

    var vm = this;
    vm.stateGo = stateGo;

    if(!$localStorage[environmental+"shopid"]){
        $localStorage.$reset();
        $state.go('login');
    }

    var shopid=$localStorage[environmental+"shopid"];
    vm.adid = $stateParams.id;
    vm.adInfo = {};

    AdvertisementService.advert(vm.adid).$promise.then(function (advert) {
        vm.adInfo.img = advert.img;
        vm.adInfo.name = advert.name;
        vm.adInfo.type = advert.adverttype;
        vm.adInfo.qrcode = advert.qrcode;
    });

    AdvertisementService.getById(vm.adid).$promise.then(function (data) {
        vm.adInfo.starttime = data[0].starttime;
        vm.adInfo.endtime = data[0].endtime;
        vm.adInfo.orderid = data[0].orderid;
    });

    //
    function stateGo(state, id) {
        $state.go(state, {adid:id});
    }
}